package controle;

import java.rmi.RemoteException;
import java.sql.SQLException;

import br.com.pedido.www.FornecedorBPrecoServicoRequest;
import br.com.pedido.www.FornecedorBPrecoServicoResponse;
import br.com.pedido.www.FornecedorBRequisicaoServicoRequest;
import br.com.pedido.www.FornecedorBRequisicaoServicoResponse;
import infra.bean.RequisicaoDeCompraBean;


public class FornecedorBServico  {
   


	public FornecedorBPrecoServicoResponse verificarPrecoMaterial(
			FornecedorBPrecoServicoRequest params) throws RemoteException {

		FornecedorBServicoParticipante part = new FornecedorBServicoParticipante(this, params);		
		double preco = 0.0; 
		FornecedorBPrecoServicoResponse fornecedorResponse = new FornecedorBPrecoServicoResponse();
		
		try {
			preco = part.verificarPrecoMaterial(params.getDescricao());
			fornecedorResponse.setPreco(preco);
			
		}  catch (SQLException e) {
			throw new RemoteException (e.getMessage());
		}

		return fornecedorResponse;
		
	}

		
	public FornecedorBRequisicaoServicoResponse efetuarRequisicaoDeCompra(
			FornecedorBRequisicaoServicoRequest params) throws RemoteException {

		FornecedorBServicoParticipante part = new FornecedorBServicoParticipante(this, params);		
		 
		FornecedorBRequisicaoServicoResponse fornecedorResponse = new FornecedorBRequisicaoServicoResponse();
		RequisicaoDeCompraBean requisicaoCompra = new RequisicaoDeCompraBean();
		requisicaoCompra.setData(params.getRequisicaoDeCompraBeanElement().getData().getTime());
		requisicaoCompra.setDescricao(params.getRequisicaoDeCompraBeanElement().getDescricaoItem());
		requisicaoCompra.setIdPedidoServico(params.getRequisicaoDeCompraBeanElement().getIdPedidoServico());
		requisicaoCompra.setQtdade(params.getRequisicaoDeCompraBeanElement().getQtdade());
		requisicaoCompra.setPreco(params.getRequisicaoDeCompraBeanElement().getPreco());
		
		
		try {
			fornecedorResponse.setConfirmacao(part.efetuarRequisicaoDeCompra(requisicaoCompra));
	
			
		}  catch (SQLException e) {
			throw new RemoteException (e.getMessage());
		}

		return fornecedorResponse;
		
	}


}
